package cn.fintecher.pangolin.service.business.web;

import cn.fintecher.pangolin.common.web.BaseController;
import cn.fintecher.pangolin.service.business.model.request.*;
import cn.fintecher.pangolin.service.business.model.response.PersonalAddressResponse;
import cn.fintecher.pangolin.service.business.model.response.PersonalContactResponse;
import cn.fintecher.pangolin.service.business.service.PersonalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Auther: xiaqun
 * @Description: 客户信息相关接口
 * @Date: 11:00 2019/9/16
 */

@RestController
@RequestMapping("/api/personalController")
@Api(value = "客户信息相关接口", description = "客户信息相关接口")
public class PersonalController extends BaseController {
    @Autowired
    private PersonalService personalService;

    /**
     * 查询客户联系人信息
     */
    @ApiOperation(value = "查询客户联系人信息", notes = "查询客户联系人信息")
    @GetMapping("/findPersonalContact")
    public ResponseEntity<List<PersonalContactResponse>> findPersonalContact(@RequestParam @ApiParam(value = "案件ID", required = true) String caseId) {
        log.info("REST request to find personal contact,{}", caseId);
        List<PersonalContactResponse> list = personalService.findPersonalContact(caseId);
        return ResponseEntity.ok().body(list);
    }

    /**
     * 查询客户地址信息
     */
    @ApiOperation(value = "查询客户地址信息", notes = "查询客户地址信息")
    @GetMapping("/findPersonalAddress")
    public ResponseEntity<List<PersonalAddressResponse>> findPersonalAddress(@RequestParam @ApiParam(value = "案件ID", required = true) String caseId) {
        log.info("REST request find personal address,{}", caseId);
        List<PersonalAddressResponse> list = personalService.findPersonalAddress(caseId);
        return ResponseEntity.ok().body(list);
    }

    /**
     * 联系方式/地址标记有效无效
     */
    @ApiOperation(value = "联系方式/地址标记有效无效", notes = "联系方式/地址标记有效无效")
    @PostMapping("/markStatus")
    public ResponseEntity<Void> markStatus(@Valid @RequestBody MarkStatusRequest request,
                                           @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to mark status,{}", request);
        personalService.markStatus(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 新增联系人信息
     */
    @ApiOperation(value = "新增联系人信息", notes = "新增联系人信息")
    @PostMapping("/addPersonalContact")
    public ResponseEntity<Void> addPersonalContact(@RequestBody AddContactRequest request,
                                                   @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to add personal contact,{}", request);
        personalService.addPersonalContact(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 新增地址信息
     */
    @ApiOperation(value = "新增地址信息", notes = "新增地址信息")
    @PostMapping("/addPersonalAddress")
    public ResponseEntity<Void> addPersonalAddress(@RequestBody AddAddressRequest request,
                                                   @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to add personal address,{}", request);
        personalService.addPersonalAddress(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改联系人信息
     */
    @ApiOperation(value = "修改联系人信息", notes = "修改联系人信息")
    @PutMapping("/modifyPersonalContact")
    public ResponseEntity<Void> modifyPersonalContact(@RequestBody ModifyContactRequest request,
                                                      @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to modify personal contact,{}", request);
        personalService.modifyPersonalContact(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改地址信息
     */
    @ApiOperation(value = "修改地址信息", notes = "修改地址信息")
    @PutMapping("/modifyPersonalAddress")
    public ResponseEntity<Void> modifyPersonalAddress(@RequestBody ModifyAddressRequest request,
                                                      @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to modify personal address,{}", request);
        personalService.modifyPersonalAddress(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除联系人/地址
     */
    @ApiOperation(value = "删除联系人/地址", notes = "删除联系人/地址")
    @DeleteMapping("/deletePersonalContact")
    public ResponseEntity<Void> deletePersonalContact(@RequestParam @ApiParam(value = "主键ID", required = true) String id,
                                                      @RequestParam @ApiParam(value = "类型", required = true) Integer type) {
        log.info("REST request to delete personal contact,{},{}", id, type);
        personalService.deletePersonalContact(id, type);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改备注
     */
    @ApiOperation(value = "修改备注", notes = "修改备注")
    @PutMapping("/modifyRemark")
    public ResponseEntity<Void> modifyRemark(@RequestBody ModifyContactRequest request,
                                             @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to modify remark,{}", request);
        personalService.modifyRemark(request, token);
        return ResponseEntity.ok().build();
    }
}